package com.tiyo.monitor.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tiyo.common.annotation.Log;
import com.tiyo.common.core.domain.AjaxResult;
import com.tiyo.common.enums.BusinessType;
import com.tiyo.framework.web.controller.BaseController;
import com.tiyo.monitor.mapper.domain.SysOperLog;
import com.tiyo.monitor.service.SysOperLogService;
/**
 * 
 * @Description 操作日志管理
 * @author yangb
 * @version v1.0
 * @date 2021年1月21日
*
 */
@RequestMapping("/monitor/operlog")
@Controller
public class SysOperLogController extends BaseController {
	private String prefix = "monitor/operlog";

    @Autowired
    private SysOperLogService sysOperLogService;

    @RequiresPermissions("monitor:operlog:view")
    @GetMapping()
    public String operlog()
    {
        return prefix + "/operlog";
    }

    @RequiresPermissions("monitor:operlog:list")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(SysOperLog operLog)
   {
        IPage<SysOperLog> page =sysOperLogService.selectOperLogList(operLog);
        return AjaxResult.success(page);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @RequiresPermissions("monitor:operlog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysOperLog operLog)
    {
        return AjaxResult.success();
    }

    @RequiresPermissions("monitor:operlog:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
    	sysOperLogService.deleteOperLogByIds(ids);
        return AjaxResult.success();
    }

    @RequiresPermissions("monitor:operlog:detail")
    @GetMapping("/detail/{operId}")
    public String detail(@PathVariable("operId") Long operId, ModelMap mmap)
    {
        mmap.put("operLog", sysOperLogService.selectOperLogById(operId));
        return prefix + "/detail";
    }
    
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @RequiresPermissions("monitor:operlog:remove")
    @PostMapping("/clean")
    @ResponseBody
    public AjaxResult clean()
    {
    	sysOperLogService.cleanOperLog();
        return success();
    }
	
}
